home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / util / time / EZCron.lha / EZCron < prev    next >
Text File  |  1996-10-03  |  10KB  |  312 lines

  1. /*          EZCron by Jim Hines v1.71 ©1995-1996 All Rights Reserved
  2. **
  3. ** 10-23-95 Added requester to verify making a NEW cron.config file. See newrtn:
  4. ** 10-25-95 Fixed Bug in the above and added renaming of the old config file. See newrtn:
  5. **             renamed from ACron to EZCron. GUI started on this date too.
  6. ** 11-30-95 added the text string reminder support and the sfx functions
  7. ** 12-05-95 Fixed case sensitivity problem with weekly, monthly & Daily routines
  8. ** 12-13-95 Added Speech Function
  9. ** 01-04-96 Added Weekdays, Weekend and Quarterly support functions
  10. ** 01-05-96 Fixed a bug in the Weekdays routine.
  11. ** 01-11-96 Cleaned up the code a bit
  12. ** 01-17-96    Added a new routine.  ie every_3_wed
  13. ** 08-25-96 Moved the cron.config file to envarc: / RAM:ENV
  14. **            Good idea Paul. ;)
  15. ** 09-02-96 Moved the active config file to ram:t as the env: was causing HD
  16. **          activity with such programs as HDEnv
  17. ** 09-10-96 Hourly time range routine added.
  18. ** 09-11-96 Fixed a nasty bug in time range and majorly rearranged the timer code.
  19. **          Version bumped to 1.70. Thanks Gene!
  20. **            Finally renamed the rexx port from ACron_Rexx to EZCron_Rexx.
  21. ** 09-18-96 Added the every 'Five_Min' time field.
  22. ** 10-03-96 Actually made it work (What took me so long?)
  23. */
  24.  
  25.     csi='9b'x
  26.     Ital=csi'3m'
  27.     bold=csi'1m'
  28.     norm=csi'0m'
  29.     black=csi'31m'
  30.     white=csi'32m'
  31.     blue=csi'33m'
  32.     LF = '0a'x
  33. /* ========END VARABLES == */
  34.  
  35.     arg command lg .
  36.  
  37.     if ~show('L','rexxsupport.library') then
  38.         call addlib('rexxsupport.library',0,-30)
  39. /*    if ~show('L','rexxreqtools.library') then
  40.             call addlib("rexxreqtools.library", 0, -30, 0)
  41. */
  42.     address command 'copy s:cron.config t:'    /*    Added 9-02-96 */
  43.  
  44.     /* ======== THIS IS THE INPUT PARSING / USAGE SECTION WITH A SUB-ROUTINE== */
  45.  
  46.     select
  47.         when command = 'START' then call startrtn()
  48.         when command = "STOP" then call stoprtn()
  49.         when command = "QUIT" then call stoprtn()
  50.     otherwise
  51.         say ''
  52.         say bold'ERROR,'norm 'Unknown option'blue command norm
  53.         call nulinp()
  54.     end
  55.  
  56. stoprtn:
  57.     if command = "STOP" then do
  58.         if showlist('P', 'EZCRON_REXX') then do
  59.             say ital 'Exiting EZCron: Please Wait. Program will exit in' LT 'seconds!' norm
  60.             address 'EZCRON_REXX' STOP
  61.             exit
  62.         end
  63.     end
  64.     else
  65.         say bold ital 'EZCron is not running.' norm
  66.         exit
  67.     end
  68.  
  69.     /* =======LOOP== */
  70. startrtn:
  71.     if ~exists('t:cron.config') then do
  72.         call rtezrequest('cron.config does NOT exist', "Okay", , "rt_reqpos = reqpos_centerscr")
  73.         exit
  74.     end
  75.  
  76.     RC = showlist('P', 'EZCRON_REXX')
  77.     if RC = 1 then do
  78.         say bold ital white 'EZCron is Already Active' norm
  79.         exit
  80.     end
  81.  
  82.     openport('EZCRON_REXX')
  83.     SIGNAL on HALT
  84.  
  85.     /* =======PARSE CONFIG FILE & TIMER SECTION == */
  86.     do forever
  87.  
  88.         sec = right(time('N'),2)   /* get seconds */
  89.         sec2 = 60 - sec        /* 60 (seconds) minus sec) */
  90.         delayvar = sec2 * 50   /* sec2 x 50 ticks or 1 second sets the delay time */
  91.         LT = delayvar / 50
  92.         LTime = 60 - LT
  93.         call delay(delayvar)    /* 3000 would be equal to 1 minute */
  94.  
  95.     /* ======== AREXX PORT STUFF == */
  96.         pkt = getpkt('EZCRON_REXX')
  97.         if pkt ~= '0000 0000'x then call aport(pkt)
  98.  
  99.         clock = time('N')
  100.         clock2 = LEFT(clock,5)
  101.         date = Date(USA)               /*   08/04/92  */
  102.         date2 = Date(S)                /*   19920804  */
  103.         date3 = Date(W, date2, 'S')    /*   Friday    */
  104.  
  105.         config = 't:cron.config'        /* Name of file for reading events from */
  106.         event. = 0
  107.  
  108.         if ~open(cronfile, config,'READ') then do
  109.             exit 20
  110.         end
  111.  
  112.         errors = 0
  113.  
  114.         do until eof(cronfile)
  115.             /* Grab the line, parse the event and ignore the comments */
  116.             linein = readln(cronfile)
  117.             parse var linein line '#'
  118.  
  119.             next = event.0 + 1
  120.  
  121.             parse var line event.next.command event.next.pargs1 event.next.pargs2,
  122.             event.next.pargs3 event.next.pargs4 event.next.time    event.next.date,
  123.             event.next.rng1 event.next.rng2 event.next.sfx event.next.txt
  124.  
  125.             event.next.date = translate(event.next.date, 'abcdefghijklmnopqrstuvwxyz',,
  126.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  127.                             /* THE ABOVE TRANSLATES THE DATE TO LOWERCASE IF NOT NUMERIC */
  128.  
  129.             event.next.time = translate(event.next.time, 'abcdefghijklmnopqrstuvwxyz',,
  130.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  131.                             /* THE ABOVE TRANSLATES THE TIME TO LOWERCASE IF NOT NUMERIC */
  132.  
  133.             select
  134.                 when event.next.command = "" then iterate
  135.                 when event.next.command = "" then do
  136.                     say "Not enough fields in:" linein
  137.                     errors =  1
  138.                     iterate
  139.                 end
  140.             otherwise event.0 = next
  141.             end
  142.         end  /* end of the do until eof loop */
  143.         call close(cronfile)
  144.  
  145.     /* ======== END OF PARSE SECTION == */
  146.  
  147.         do i = 1 to event.0
  148.  
  149.     /* ======= Arguments Routine == */
  150.             if event.i.pargs1 = '-' then event.i.pargs1 = ''
  151.             if event.i.pargs2 = '-' then event.i.pargs2 = ''
  152.             if event.i.pargs3 = '-' then event.i.pargs3 = ''
  153.             if event.i.pargs4 = '-' then event.i.pargs4 = ''
  154.  
  155.     /* ======= Misc Routines == */
  156.             if event.i.sfx = '-' then event.i.sfx = ''
  157.             if event.i.txt = '-' then event.i.txt = ''
  158.  
  159.     /* ======= Every Minute Routine == */
  160.             if event.i.time = 'minute' then event.i.time = clock2
  161.  
  162.     /* ======= Every Five Minute Routine ==  */
  163.             if event.i.time = 'five_min' then do
  164.                 parse var clock2 dontneedme ':' minfive
  165.                 fiveresult = minfive / 5
  166.                 parse var fiveresult intmin '.' decsec
  167.             end
  168.             if decsec = '' then event.i.time = clock2   /* if there is a remainder, get out!! */
  169.             drop dontneedme minfive fiveresult intmin decsec
  170.  
  171.     /* ======= Quarterly Routine == */
  172.             parse var clock2 hrs ':' min
  173.             drop hrs
  174.             if min = 00 & event.i.time = 'quarterly' then event.i.time = clock2
  175.             if min = 15 & event.i.time = 'quarterly' then event.i.time = clock2
  176.             if min = 30 & event.i.time = 'quarterly' then event.i.time = clock2
  177.             if min = 45 & event.i.time = 'quarterly' then event.i.time = clock2
  178.  
  179.     /* ======= Every Hour Routine == */
  180.             if min = 00 & event.i.time = 'hourly' then event.i.time = clock2
  181.  
  182.     /* ======= Daily Routine == */
  183.             if event.i.date = 'daily' then event.i.date = date
  184.  
  185.     /* ======= Weekly Routine == */
  186.  
  187.             if event.i.date = 'sunday' & date3 = 'Sunday' then event.i.date = date
  188.             if event.i.date = 'monday' & date3 = 'Monday' then event.i.date = date
  189.             if event.i.date = 'tuesday' & date3 = 'Tuesday' then event.i.date = date
  190.             if event.i.date = 'wednesday' & date3 = 'Wednesday' then event.i.date = date
  191.             if event.i.date = 'thursday' & date3 = 'Thursday' then event.i.date = date
  192.             if event.i.date = 'friday' & date3 = 'Friday' then event.i.date = date
  193.             if event.i.date = 'saturday' & date3 = 'Saturday' then event.i.date = date
  194.  
  195.     /* ======= Weekdays Routine == The 'ol Mon-Fri routine */
  196.             if event.i.date = 'weekdays' & date3 ~= 'Sunday' & date3 ~= 'Saturday'
  197.                 then event.i.date = date
  198.  
  199.     /* ======= Weekend Routine == The ol' Sat & Sun routine */
  200.             if event.i.date = 'weekend' & date3 = 'Saturday' then event.i.date = date
  201.             if event.i.date = 'weekend' & date3 = 'Sunday' then event.i.date = date
  202.  
  203.     /* ======= Monthly Routine == */
  204.             month.event = event.i.date
  205.             parse var month.event mth '-' day2
  206.             if mth = 'monthly' then do
  207.                 parse var date month '/' day '/' year
  208.                 if day2 = day & event.i.time = clock2 then event.i.date = date
  209.             end
  210.  
  211.     /* ======= # 4th Fri, 2nd Tue, etc routine == */
  212.  
  213.              parse var event.i.date var1 '_' num '_' dow  /* every 2 wed */
  214.             if var1 = 'every' then do
  215.                 del3 = date(n)   /* 20 Apr 88 */
  216.                 parse var del3 del1 cm del2
  217.                 drop del1 del2 /* dont even need them */
  218.  
  219.                 if cm = 'Jan' then cm = 31;if cm = 'Feb' then cm = 28 /* This is for 1996. Will need to be changed to 28 after Feb 29. */
  220.                 if cm = 'Mar' then cm = 31;if cm = 'Apr' then cm = 30
  221.                 if cm = 'May' then cm = 31;if cm = 'Jun' then cm = 30
  222.                 if cm = 'Jul' then cm = 31;if cm = 'Aug' then cm = 31
  223.                 if cm = 'Sep' then cm = 30;if cm = 'Oct' then cm = 31
  224.                 if cm = 'Nov' then cm = 30;if cm = 'Dec' then cm = 31
  225.                 countvar = 0
  226.  
  227.                 do z = 1 to cm
  228.                     currdate = date(s)                /* 19951221 year month day     */
  229.                     yearmonth = left(currdate, 6)    /* 199512     year month        */
  230.  
  231.                     if z < 10 then do
  232.                         zdate = yearmonth'0'z   /* 19951201 */
  233.                         newz = '0'z
  234.                     end
  235.                     else do
  236.                         zdate = yearmonth''z   /* 19951231 */
  237.                         newz = z
  238.                     end
  239.  
  240.                     myday = Date(W, zdate, 'S')   /* Friday   */
  241.                     myday = left(myday, 3)         /* Fri         */
  242.                     myday = translate(myday, 'abcdefghijklmnopqrstuvwxyz',,
  243.                                     'ABCDEFGHIJKLMNOPQRSTUVWXYZ') /* fri */
  244.  
  245.                     if myday = dow then countvar = countvar + 1
  246.                     if myday = dow & countvar = num then do
  247.                         year = left(zdate, 4)             /* 1995     */
  248.                         year2 = right(year, 2)             /*   95     */
  249.                         month = right(zdate, 4)            /*     1221 */
  250.                         month2 = left(month, 2)         /*       12    */
  251.                         event.i.date = month2'/'newz'/'year2
  252.                         leave
  253.                     end
  254.                 end
  255.             end
  256.  
  257.  
  258.     /* ======= Time Range routine == */
  259.  
  260.             range = ''
  261.             hrs = time(h)
  262.             if hrs < 10 then hrs = 0||hrs
  263.             if event.i.rng1 ~= '--' then do
  264.                 if event.i.rng1 <= hrs & event.i.rng2 > hrs then do
  265.                     range = runitnow
  266.                 end
  267.             if range ~= runitnow then event.i.time = void_event
  268.             end
  269.  
  270.  
  271.     /* ======= Final Routine == */
  272.  
  273.                if event.i.time = clock2 & event.i.date = date then
  274.                 address command 'run >NIL:' event.i.command event.i.pargs1,
  275.                 event.i.pargs2 event.i.pargs3 event.i.pargs4
  276.  
  277.             if event.i.time = clock2 & event.i.date = date & event.i.sfx ~= "" then do
  278.                 if exists('EZCron:prefs/sfx.prefs') then do
  279.                     open(sfxconfig, 'EZCron:prefs/sfx.prefs', 'r')
  280.                     sfxplayer = readln(sfxconfig)
  281.                     close(sfxconfig)
  282.                     address command 'run >nil:' sfxplayer event.i.sfx
  283.                 end
  284.             end
  285.  
  286.             if event.i.time = clock2 & event.i.date = date & event.i.txt ~= "" then do
  287.                 address command 'run >nil: rx >nil: ezcron:rexx/Reminder.rexx' event.i.txt /*This calls the external rexx proggy for the event display */
  288.                 if showlist(h,SPEAK) then do
  289.                         address command 'echo' event.i.txt '>speak:'
  290.                 end
  291.             end
  292.  
  293.             if event.i.time = clock2 & event.i.date = date
  294.             then event.i.date = 'Finished with Event'
  295.  
  296.         end       /* end of 'do i = 1 to event.0' */
  297.     end             /* end of do forever */
  298.  
  299.  
  300. /* ======== CLEANUP == */
  301.     if event.0 = 0 then exit
  302.     options failat 300
  303.     trace 'Off'
  304.  
  305. /* ======== Arexx Port Message Check == */
  306. aport:
  307.     Cmd = getarg(Pkt)
  308.     if Cmd = 'STOP' then do
  309.         call reply(Pkt, rc)
  310.         exit
  311.     end
  312.